/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.chl.da.controllerBeans;

import edu.chl.da.ejb.core.Airport;
import edu.chl.da.ejb.core.AirportPK;
import edu.chl.da.ejb.ctrl.IManageAirport;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 * Controller bean managing listing, getting and removal events of airports
 * @author Kristofer
 */
@ManagedBean(name = "ManageAirportController")
@RequestScoped
public class ManageAirportController {

    private AirportPK selectedAirport;
    
    @EJB
    IManageAirport ima;

    public ManageAirportController() {

    }

    public String deleteAirport() {
        Airport a = ima.getAirport(selectedAirport);
        if (ima.removeAirport(a)) {
            return "/admin/manageAirports.jsf?faces-redirect=true";
        } else {
            FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage("Gick ej att radera flygplatsen, kontrollera eventuella resmal"));
           return null; //Same page;

        }
    }

    public AirportPK getSelectedAirport() {
        return selectedAirport;
    }

    public void setSelectedAirport(AirportPK selectedAirport) {
        this.selectedAirport = selectedAirport;
    }
}
